<?php


namespace App\HttpController\Api;

use \EasySwoole\Component\Di;
use App\Model\Video as VideoModel;
use EasySwoole\FastCache\Cache;
use App\Lib\Cache\Video as VideoCache;

class Index extends Base
{

    public function index()
    {
        
    }

    public function lists()
    {
        $catId = $this->params['cat_id'];
        $condition = [
            'cat_id' => $this->params['cat_id']
        ];
        // $videoFile = EASYSWOOLE_ROOT.'/webroot/video/json/'.$catId.'.json';
        // $videoData = is_file($videoFile) ? file_get_contents($videoFile) : [];
        // $videoData = Cache::getInstance()->get('index_video_data_cat_id_'.$catId);
        // $videoData = Di::getInstance()->get('REDIS')->get('index_video_data_cat_id_'.$catId);
        // $videoData = !empty($videoData) ? json_decode($videoData,true) : [];
        // $videoData = !empty($videoData) ? $videoData : [];
        try{
            $videoData = (new VideoCache())->getCache($catId);
        }catch(\Expceiton $e){
            throw new \Expcetion('参数错误');
        }
        $count = count($videoData);
        return $this->writeJson(200,'OK',$this->getPagingDatas($count, $videoData));
    }

    public function getMysql()
    {
        $config = new \EasySwoole\Mysqli\Config([
            'host'          => '127.0.0.1',
            'port'          => 3306,
            'user'          => 'root',
            'password'      => '123456',
            'database'      => 'demo',
            'timeout'       => 5,
            'charset'       => 'utf8mb4',
        ]);
        $client = new \EasySwoole\Mysqli\Client($config);
        go(function ()use($client){
            $client->queryBuilder()->get('user');
            var_dump($client->execBuilder());
        });
    }

    public function getRedis()
    {
        $data = Redis::getInstance()->get('fuck','');
        return $this->writeJson(200,'OK',$data);
    }

}